import React from 'react';
import { Button, ButtonProps } from "antd";


import { withModal, mountModal } from "vendor/components/pro-hoc/withModal";
import CreateOrEdit from './CreateOrEdit';
import { RespDataType } from "../../../api";

interface CreateOrEditBtnProps extends ButtonProps {
  menuId?: number;
  optType: "add" | "edit";
  fetchList: () => void;
  editData?: RespDataType.MenuItem
}

const CreateOrEditBtn: React.FC<CreateOrEditBtnProps> = ({ menuId, optType, fetchList, editData, ...restProps }) => {

  return (
    <Button
      onClick={() => {
        const CreateOrEditModal = withModal(CreateOrEdit);
        mountModal(<CreateOrEditModal modalProps={{ title: `${optType == "add" ? "添加" : "编辑"}菜单` }} optType={optType} menuId={menuId} fetchList={fetchList} editData={editData} />)
      }}
      {...restProps}
    />
  )
};

export default CreateOrEditBtn;
